package com.whynot.frame.designMode.proxy.jdkdynamic.main;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

import com.whynot.frame.designMode.proxy.jdkdynamic.UserServiceDynamicProxy;
import com.whynot.frame.designMode.proxy.jdkdynamic.service.UserService;
import com.whynot.frame.designMode.proxy.jdkdynamic.service.UserServiceImpl;
import com.whynot.frame.designMode.proxy.jdkdynamic.UserServiceDynamicProxy;
import com.whynot.frame.designMode.proxy.jdkdynamic.service.UserService;
import com.whynot.frame.designMode.proxy.jdkdynamic.service.UserServiceImpl;

public class ProxyClient {
	
	public static void main(String[] args) {
		UserService userService = new UserServiceImpl();
		InvocationHandler handler = new UserServiceDynamicProxy(userService);
		Class<?> clazz = userService.getClass();
		/**
		 * 通过代理，给UserService指定代理UserServiceDynamicProxy实现
		 */
		UserService proService = (UserService) Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), handler);
		proService.getUserName();
	}
}
